package com.gaohe.post.controller;

import java.util.List;
import java.io.IOException;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.gaohe.common.log.annotation.Log;
import com.gaohe.common.log.enums.BusinessType;
import com.gaohe.common.security.annotation.RequiresPermissions;
import com.gaohe.post.domain.FmPostView;
import com.gaohe.post.service.IFmPostViewService;
import com.gaohe.common.core.web.controller.BaseController;
import com.gaohe.common.core.web.domain.AjaxResult;
import com.gaohe.common.core.utils.poi.ExcelUtil;
import com.gaohe.common.core.web.page.TableDataInfo;

/**
 * 帖子围观Controller
 * 
 * @author ruoyi
 * @date 2025-06-03
 */
@RestController
@RequestMapping("/view")
public class FmPostViewController extends BaseController
{
    @Autowired
    private IFmPostViewService fmPostViewService;

    /**
     * 查询帖子围观列表
     */
    @RequiresPermissions("post:view:list")
    @GetMapping("/list")
    public TableDataInfo list(FmPostView fmPostView)
    {
        startPage();
        List<FmPostView> list = fmPostViewService.selectFmPostViewList(fmPostView);
        return getDataTable(list);
    }

    /**
     * 导出帖子围观列表
     */
    @RequiresPermissions("post:view:export")
    @Log(title = "帖子围观", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FmPostView fmPostView)
    {
        List<FmPostView> list = fmPostViewService.selectFmPostViewList(fmPostView);
        ExcelUtil<FmPostView> util = new ExcelUtil<FmPostView>(FmPostView.class);
        util.exportExcel(response, list, "帖子围观数据");
    }

    /**
     * 获取帖子围观详细信息
     */
    @RequiresPermissions("post:view:query")
    @GetMapping(value = "/{postViewId}")
    public AjaxResult getInfo(@PathVariable("postViewId") Long postViewId)
    {
        return success(fmPostViewService.selectFmPostViewByPostViewId(postViewId));
    }

    /**
     * 新增帖子围观
     */
    @RequiresPermissions("post:view:add")
    @Log(title = "帖子围观", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FmPostView fmPostView)
    {
        return toAjax(fmPostViewService.insertFmPostView(fmPostView));
    }

    /**
     * 修改帖子围观
     */
    @RequiresPermissions("post:view:edit")
    @Log(title = "帖子围观", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FmPostView fmPostView)
    {
        return toAjax(fmPostViewService.updateFmPostView(fmPostView));
    }

    /**
     * 删除帖子围观
     */
    @RequiresPermissions("post:view:remove")
    @Log(title = "帖子围观", businessType = BusinessType.DELETE)
	@DeleteMapping("/{postViewIds}")
    public AjaxResult remove(@PathVariable Long[] postViewIds)
    {
        return toAjax(fmPostViewService.deleteFmPostViewByPostViewIds(postViewIds));
    }
}
